# Maintainer: Maksim Bondarenkov <maksapple2306@gmail.com>

_realname=alacritty
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.12.2
pkgrel=1
pkgdesc="A cross-platform, OpenGL terminal emulator (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang32' 'clang64') # 'clangarm64')
url="https://github.com/alacritty/alacritty"
license=('spdx:Apache-2.0 OR MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-rust"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ncurses"
             "${MINGW_PACKAGE_PREFIX}-desktop-file-utils"
             'git')
depends=("${MINGW_PACKAGE_PREFIX}-freetype"
         "${MINGW_PACKAGE_PREFIX}-fontconfig")
checkdepends=("${MINGW_PACKAGE_PREFIX}-ttf-dejavu")
optdepends=("${MINGW_PACKAGE_PREFIX}-ncurses: for alacritty terminfo database")
source=("git+${url}.git#tag=v${pkgver}?signed")
validpgpkeys=('4DAA67A9EA8B91FCC15B699C85CDAE3C164BA7B4'  # Christian Dürr <contact@christianduerr.com>
              'A56EF308A9F1256C25ACA3807EA8F8B94622A6A9') # Kirill Chibisov <contact@kchibisov.com>
sha256sums=('SKIP')

prepare() {
  cd "${srcdir}/${_realname}"

  # https://github.com/msys2/MINGW-packages/pull/17827#issuecomment-1646226014
  # if [[ $MINGW_PACKAGE_PREFIX == *-clang-aarch64 ]]; then
    # cargo fetch --locked --target aarch64-pc-windows-gnullvm
  # else
    cargo fetch --locked --target "${CARCH}-pc-windows-gnu"
  # fi
}

build() {
  cd "${srcdir}"
  rm -rf "build-${MSYSTEM}" | true
  cp -r "${_realname}" "build-${MSYSTEM}"
  cd "build-${MSYSTEM}"

  WINAPI_NO_BUNDLED_LIBRARIES=1 \
    "${MINGW_PREFIX}/bin/cargo.exe" build \
    --release \
    --locked
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"

  "${MINGW_PACKAGE_PREFIX}/bin/cargo.exe" test \
    --release \
    --locked
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  install -Dm755 "target/release/${_realname}.exe" "${pkgdir}${MINGW_PREFIX}/bin/${_realname}.exe"
  install -Dm644 "extra/alacritty.man" "${pkgdir}${MINGW_PREFIX}/share/man/man1/alacritty.1"
  install -Dm644 "extra/alacritty-msg.man" "${pkgdir}${MINGW_PREFIX}/share/man/man1/alacritty-msg.1"
  install -Dm644 "alacritty.yml" "${pkgdir}${MINGW_PREFIX}/share/doc/alacritty/example/alacritty.yml"
  install -Dm644 "extra/completions/alacritty.bash" "${pkgdir}${MINGW_PREFIX}/share/bash-completion/completions/alacritty"
  install -Dm644 "extra/completions/_alacritty" "${pkgdir}${MINGW_PREFIX}/share/zsh/site-functions/_alacritty"
  install -Dm644 "extra/completions/alacritty.fish" "${pkgdir}${MINGW_PREFIX}/share/fish/vendor_completions.d/alacritty.fish"
  install -Dm644 "extra/logo/alacritty-term.svg" "${pkgdir}${MINGW_PREFIX}/share/pixmaps/Alacritty.svg"
}
